package com.zx.stat.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zx.stat.domain.BaseEntity;
import com.zx.stat.mapper.StatMapper;
import com.zx.stat.service.StatService;

@Service
public class StatServiceImpl implements StatService {

	@Autowired
	private StatMapper statMapper;
	
	@Override
	public List<BaseEntity> loadCustomerAreaStatJosn() {
		return statMapper.loadCustomerAreaStatJosn();
	}

	@Override
	public Map<String, Object> loadOpernameYearGradeStat(String year) {
		List<BaseEntity> list = statMapper.loadOpernameYearGradeStat(year);
		Map<String, Object> map = new HashMap<String, Object>();
		List<String> names = new ArrayList<String>();
		List<Double> values = new ArrayList<Double>();
		for (int i = 0; i < list.size(); i++) {
			names.add(list.get(i).getName());
			values.add(list.get(i).getValue());
		}
		map.put("name", names);
		map.put("value", values);
		return map;
	}

	@Override
	public List<Double> loadCompanyYearGradeStat(String year) {
		List<Double> list = statMapper.loadCompanyYearGradeStat(year);
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i)==null){
				list.set(i, 0d);
			}
		}
		return list;
	}

}
